package com.yanshaohui.springboot

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.Bean

import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2

@SpringBootApplication
@EnableSwagger2
@EnableCaching
class SpringbootGroovyApplication {

	static main(args) {
		SpringApplication.run(SpringbootGroovyApplication.class, args);
	}

	@Bean
	def Docket createRestApi() {
		new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.yanshaohui.springboot.controller"))
				.paths(PathSelectors.any())
				.build();
	}

	def ApiInfo apiInfo() {
		new ApiInfoBuilder()
				.title("Spring Boot使用Groovy")
				.description("参照我的码云地址：http://git.oschina.net/yanshaohui/")
				.termsOfServiceUrl("http://git.oschina.net/yanshaohui")
				.contact(new Contact("老码农的菜园","http://git.oschina.net/yanshaohui/","yanshaohui@live.com"))
				.version("0.1")
				.build();
	}
}
